<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<?php 
	$ci = & get_instance();
	if(!isUserLogin()){
		redirect(site_url());exit();
	}
	$USER = $ci->user_entity->init('id', getUserId());
	$listPackages = $ci->coin_packages_entity->getCoinPackagesType('online');
?>
<div id="center_content">
	<div class="clrboth"></div>
	<div class="block">
		<div class="title" style="position:relative;">
			<h3 class="bold"><a href="<?php echo site_url("cricket/user/dashboard")?>">Dashboard</a> &raquo; Add CX coins</h3>
			<a class="back_button2" href="<?php echo site_url("cricket/user/dashboard")?>" title="Back?">Back?</a>	
		</div>
		<div class="clrboth"></div>
		<div class="content">
			<div class="rowitem3">
				<div class="clrboth"></div>
					<?php $this->load->view('cricket/user/payment_modes'); ?>
				<div class="clrboth"></div>	
				<br/>
				1. Choose a Package
				<div class="clrboth"></div>	
				
				<table class="summary">
					<thead>
						<td width="10%">Select</td>
						<td width="40%">Package</td>
						<td width="25%">Amount (INR)</td>
						<td width="25%">Coin</td>
					</thead>
					<tbody>
						<?php foreach($listPackages as $item): ?>
							<?php $PACKAGE = $ci->coin_packages_entity->init('id', $item->id); ?>
							<tr>
								<td><input type="radio" name="package" value="<?php echo $PACKAGE->getId();?>" style="cursor:pointer;" /></td>
								<td><?php echo $PACKAGE->getPackage();?></td>
								<td style="text-align:right;"><?php echo format_Money($PACKAGE->getCost(),true);?>&nbsp;</td>
								<td style="text-align:right;"><?php echo $PACKAGE->getCoin();?>&nbsp;</td>
							</tr>
						<?php endforeach;?>
					</tbody>
				</table>
				<div class="clrboth"></div>
				
				<br/>
				2. Payment Options
				<div class="clrboth"></div>
				<br/>
				<div id="ccavenue" style="float:left;margin-left:50px;">
					<img src="<?php echo site_url();?>/addons/default/themes/clicxa/css/images/ccavanue.png" />
				</div>
				
				<div id="paypal" style="float:left;margin-left:100px;cursor:pointer;">
					<img src="<?php echo site_url();?>/addons/default/themes/clicxa/css/images/paypal.png" />
				</div>	
			</div>	
		</div>
	</div>	
	<div class="clrboth"></div>
</div>

<script type="text/javascript">
	google.setOnLoadCallback(function() {
		$('#online_payment').addClass('current');
		
		$('#paypal').bind('click',function(){
			$pack= $('input[name=package]:checked').val();
			if(!isNaturalNumber($pack)){
				alert("Please select a package firstly.");
				return false;
			}
			queryURL(BASE_URI + "cricket/account/submit_addcoins_paypal?pid="+$pack);
		});
	});
	
	//deprecated
	function addCoins(pid){
		jQuery.post(BASE_URI+'cricket/account/add_coins_submit',{ pid:pid },function(res){
			if(res== 'ok'){
				reload();
			}else{
				alert(res);
			}
		});
	}  
	
	function addFromBonus(){
		jQuery.post(BASE_URI+'cricket/account/add_coins_from_bonus',{},function(res){
			if(res== 'ok'){
				reload();
			}else{
				alert(res);
			}
		});
	}
</script>
